package com.xuptGurantee.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuptGurantee.system.common.R;
import com.xuptGurantee.system.dto.MatchDto;
import com.xuptGurantee.system.entity.Matcher;
import com.xuptGurantee.system.service.MatchDtoService;
import com.xuptGurantee.system.service.MatcherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author zzzhc
 * @version 1.0
 * @description: TODO
 * @date 2022/11/1 11:29
 */
@Slf4j
@RequestMapping("/match")
@RestController
public class MatcherController {
    @Resource
    MatcherService matcherService;

    @Resource
    MatchDtoService matchDtoService;


    @PostMapping("/regis")
    public R<String> matchVolAndAct(@RequestBody Matcher matcher) {
        matcherService.save(matcher);
        return R.success("报名成功");
    }

    @GetMapping("/cancelRegis")
    public R<String> cancelRegis(@RequestParam Long volunteerId,@RequestParam Long activityId) {
        LambdaQueryWrapper<Matcher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Matcher::getVolunteerId,volunteerId);
        queryWrapper.eq(Matcher::getActivityId,activityId);
        if (matcherService.remove(queryWrapper)) {
            return R.success("取消成功");
        }
        return R.error("取消失败");
    }

    @PostMapping("/matchInfo")
    public R<Page> getMatchInfo(@RequestBody MatchDto matchDto){
        List<MatchDto> matchDtoList = matchDtoService.getMatchDtoList(matchDto);
        Page pageInfo = new Page(matchDto.getPage(), matchDto.getPageSize());
        pageInfo.setRecords(matchDtoList);
        return R.success(pageInfo);
    }

}
